﻿using B.S.BasicData.Api.Read.Application.Command.Menu;
using B.S.BasicData.Api.Read.DTO;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.Menu
{
    public class GetMenuZiHandler : IRequestHandler<GetMenuZiCommand, ApiResult<List<MenuDTO>>>
    {
        private readonly IBaseRepository<MenuModel> menuRepo;

        public GetMenuZiHandler(IBaseRepository<MenuModel> menuRepo)
        {
            this.menuRepo = menuRepo;
        }
        public Task<ApiResult<List<MenuDTO>>> Handle(GetMenuZiCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MenuDTO>> res = new ApiResult<List<MenuDTO>>();
            var info = menuRepo.GetAll().Where(x => x.Pid == request.Id);
            if (info.Count()>0)
            {
                res.Code = ApiEnum.Success;
                res.Msg = "有子集";
            }
            else
            {
                res.Code = ApiEnum.Error;
                res.Msg = "没有子集";
            }
            return Task.FromResult(res);
        }
    }
}
